package lock;
/*
3个窗口卖100张票
 */
public class Test1 {
    public static void main(String[] args) {
        TicketTask task = new TicketTask();
        Thread t1 = new Thread(task,"窗口1");
        Thread t2 = new Thread(task,"窗口2");
        Thread t3 = new Thread(task,"窗口3");
        t1.start();
        t2.start();
        t3.start();
    }
}
class TicketTask implements Runnable {
    private Object o = new Object();
    private int tikets = 100;

    @Override
    public void run() {
        while(true){
            // 同步代码块：上锁
            synchronized (o){
                if (tikets<=0){
                    break;
                }
                System.out.println(Thread.currentThread().getName()+"卖出了第"+tikets+"张票");
                tikets--;
            }

        }
    }
}